package com.qersoft.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qersoft.dao.DictionaryDao;
import com.qersoft.entity.Dictionary;
import org.springframework.stereotype.Service;

@Service("dictionaryService")
public class DictionaryServiceImpl extends ServiceImpl<DictionaryDao, Dictionary> implements DictionaryService{
    @Override
    public Integer add(Dictionary dic) {
        return baseMapper.insert(dic);
    }

    @Override
    public IPage<Dictionary> list(Dictionary dic, Integer pageNo, Integer pageSize) {
        LambdaQueryWrapper<Dictionary> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(Dictionary::getDicName, dic.getDicName());

        int curpage = 1;
        int limit = 10;
        if (pageNo != null && pageNo > 0) {
            curpage = pageNo;
        }
        if (pageSize != null && pageSize > 0) {
            limit = pageSize;
        }

        IPage<Dictionary> page = Page.of(curpage, limit);

        return baseMapper.selectPage(page, wrapper);
    }
}


